package com.home.demo.security;




import com.home.demo.entity.vo.user.UserLoginVO;
import com.home.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class SecurityUserDetailServerImpl implements UserDetailsService {
    @Autowired
    private UserService userService;

    /**
     * 重写该方法,将校验方式换成数据库查询
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //拿username校验数据库
        UserLoginVO userEntity = userService.selectUserInfo(username);
        if (userEntity!=null){
            return new SecurityUserDetailsImpl(userEntity);
        }
        return null;
    }


}
